package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.VipDao;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.Vip;
import com.qfedu.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class VipServiceImpl implements VipService {
    @Autowired
    private VipDao vipDao;
    @Override
    //查询所有vip
    public ResponseData<List<Vip>> findAllVip(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Vip> vipList = vipDao.findAllVip();
        PageInfo pageInfo = new PageInfo(vipList);
        int count = (int) pageInfo.getTotal();
        ResponseData<List<Vip>> responseData = new ResponseData<>();
        responseData.setData(vipList);
        responseData.setCode(0);
        responseData.setCount(count);
        responseData.setMsg("ok");
        return responseData;
    }
    //申请vip
    public boolean addVip(Vip vip){
        int result = vipDao.addVip(vip);
        if(result>0){
          return true;
      }
        return false;
    }
}
